local skel = fk.CreateSkill {
  name = "lb_zero__yishan",
  tags = {Skill.Combo},
}

Fk:loadTranslationTable{
  ["lb_zero__yishan"] = "一闪",
  [":lb_zero__yishan"] = "<b><a href='lb_zero__yishan_combo-href'>连招技</a></b>（牌+牌+牌，含有至少一张「<b>锡躯</b>」牌或无目标牌），你可以选择一项：摸一张牌；或于本回合结束时重置一个<a href=':lb_zero__xiqu'><font color='red'>〖锡躯〗</font></a>。",

  ["lb_zero__yishan_combo-href"] = "发动时机：你使用牌时<br>发动条件：连招记录的牌数和等于三，且至少一张连招牌为「<b>锡躯</b>」牌或无目标牌",

  ["@lb_zero__yishan"] = "一闪",
  ["@lb_zero__yishans-turn"] = "重置锡躯",
  ["#lb_zero__yishan-choice"] = "一闪：请选择一项！",
  ["reset_xiqu"] = "重置锡躯",

  ["$lb_zero__yishan1"] = "就是现在。",
  ["$lb_zero__yishan2"] = "轻敌的后果。",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
      data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[skel.name]
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@lb_zero__yishan", 0)
    local choice = room:askToChoice(player, {
      choices = {"draw1", "reset_xiqu"},
      prompt = "#lb_zero__yishan-choice",
      skill_name = skel.name,
    })
    if choice == "draw1" then
      player:drawCards(1, skel.name)
    elseif choice == "reset_xiqu" then
      room:addPlayerMark(player, "@lb_zero__yishans-turn", 1)
    end
  end,
})

skel:addEffect(fk.TurnEnd, {
  mute = true,
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@lb_zero__yishans-turn") > 0 and not player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    for i = 0, 110, 1 do
      local name = i == 0 and "lb_zero__xiqu" or "lb_zero"..i.."__xiqu"
      if player:hasSkill(name, true) and player:usedSkillTimes(name, Player.HistoryGame) > 0 and player:getMark("@lb_zero__yishans-turn") > 0 then
        player.room:removePlayerMark(player, "@lb_zero__yishans-turn", 1)
        player:setSkillUseHistory(name, 0, Player.HistoryGame)
      end
    end
  end,
})

skel:addEffect(fk.AfterCardUseDeclared, {
  mute = true,
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if #player:getTableMark("@lb_zero__yishan") >= 3 then
      local x, y
      x = player:getTableMark("@lb_zero__yishan")[2]
      y = player:getTableMark("@lb_zero__yishan")[3]
      room:setPlayerMark(player, "@lb_zero__yishan", {x, y})
    end
    if (data.extra_data or {}).using_lb_zeroxiqu == player.id or #data.tos == 0 then
      room:addTableMark(player, "@lb_zero__yishan", "<font color=\"green\">▲</font>")
    else
      room:addTableMark(player, "@lb_zero__yishan", "<font color=\"yellow\">▼</font>")
    end
    if #player:getTableMark("@lb_zero__yishan") >= 3 and table.contains(player:getTableMark("@lb_zero__yishan"), "<font color=\"green\">▲</font>") then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[skel.name] = true
    return
    end
  end,
})

skel:addEffect(fk.PreCardUse, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true) and table.find(Card:getIdList(data.card), function(id)
    return Fk:getCardById(id):getMark("@@lb_zero__xiqu") ~= 0 end)
  end,
  on_refresh = function (self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.using_lb_zeroxiqu = player.id
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "@[lb_zero__xiqu]lb_zero__xiqu", 1)
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@lb_zero__yishan", 0)
  if not player:hasSkill("lb_zero__wanwo", true) then
    local function xiqu()
      for i = 0, 110, 1 do
        local skill = i == 0 and "lb_zero__xiqu" or "lb_zero" .. i .. "__xiqu"
        if player:hasSkill(skill, true) then
          return true
        end
      end
    end
    if not xiqu() then
      player.room:setPlayerMark(player, "@[lb_zero__xiqu]lb_zero__xiqu", 0)
    end
  end
end)

return skel
